﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OLTS.DAL;
using OLTS.MODEL;

namespace OLTS.DATA_SERVICE
{
    public class AsSignProject_Service
    {
        private OTS_ASSIGN_PROJECT _objApp = new OTS_ASSIGN_PROJECT();
        private String _empId;
        public AsSignProject_Service(OTS_ASSIGN_PROJECT objApp)
        {
            _objApp = objApp;
        }
        public AsSignProject_Service(String empId)
        {
            _empId = empId;
        }
        public AsSignProject_Service()
        {

        }
        public List<OTS_ASSIGN_PROJECT> GetAll()
        {
            using (var ctx = new Entities())
            {
                var list = ctx.OTS_ASSIGN_PROJECT.Include("OTS_PROJECT").Include("OTS_EMPLOYEE").Where(x=> x.STATUS == true && x.OTS_PROJECT.STATUS == true).ToList();
                return list;
            }
        }
        public OTS_ASSIGN_PROJECT GetByEmpId()
        {
            using (var ctx = new Entities())
            {
                var list = ctx.OTS_ASSIGN_PROJECT.Include("OTS_PROJECT").Where(x => x.EMPLOYEE_ID == _empId && x.OTS_PROJECT.STATUS == true).FirstOrDefault();
                return list;
            }
        }
        public void Add()
        {
            using (var ctx = new Entities())
            {
                ctx.OTS_ASSIGN_PROJECT.AddObject(_objApp);
                ctx.SaveChanges();
            }
        }

        public void Edit()
        {

        }

        public void Delete()
        {
            using (var ctx = new Entities())
            {
                var obj = ctx.OTS_ASSIGN_PROJECT.Where(x => x.ID == _objApp.ID).FirstOrDefault();
                if (obj != null)
                {
                    obj.STATUS = false;
                }
               // ctx.OTS_ASSIGN_PROJECT.DeleteObject(obj);
                ctx.SaveChanges();
            }
        }
    }
}
